/* @(#)FmmPerspective.java
** 
** Copyright (C) 2012 by Steven D. Stamps
**
**             Trademarks & Copyrights
** Flywheel Management Science(TM), Flywheel Management Model(TM),
** Flywheel Story Editor(TM) and FlywheelMS(TM) are exclusive trademarks
** of Steven D. Stamps and may only be used freely for the purpose of
** identifying the unforked version of this software.  Subsequent forks
** may not use these trademarks.  All other rights are reserved.
** and FlywheelMS(TM) are exclusive trademarks of Steven D. Stamps
** and may only be used freely for the purpose of identifying the
** unforked version of this software.  Subsequent forks (if any) may
** not use these trademarks.  All other rights are reserved.
**
** DecKanGL (Decorated Kanban Glyph Language) and TribKn (Tribal Knowledge)
** are also exclusive trademarks of Steven D. Stamps.  These may be used
** freely within the unforked FlywheelMS application and documentation.
** All other rights are reserved.
**
** Trademark information is available at
** <http://www.flywheelms.com/trademarks>
**
** Flywheel Management Science(TM) is a copyrighted body of management
** metaphors, governance processes, and leadership techniques that is
** owned by Steven D. Stamps.  These copyrighted materials may be freely
** used, without alteration, by the community (users and developers)
** surrounding this GPL3-licensed software.  Additional copyright
** information is available at <http://www.flywheelms.org/copyrights>
**
**              GPL3 Software License
** This program is free software: you can use it, redistribute it and/or
** modify it under the terms of the GNU General Public License, version 3,
** as published by the Free Software Foundation. This program is distributed
** in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
** even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
** PURPOSE.  See the GNU General Public License for more details. You should
** have received a copy of the GNU General Public License, in a file named
** COPYING, along with this program.  If you cannot find your copy, see
** <http://www.gnu.org/licenses/gpl-3.0.html>.
*/
package com.flywheelms.library.fmm.perspective;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;

import com.flywheelms.library.R;
import com.flywheelms.library.fmm.helper.FmmHelper;
import com.flywheelms.library.fmm.node.impl.enumerator.FmmNodeDictionary;
import com.flywheelms.library.fmm.node.interfaces.horizontal.FmmNode;

public enum FmmPerspective {

	STRATEGIC_PLANNING (
		R.string.perspective__strategic_planning,
		R.drawable.perspective__strategic_planning,
		R.id.context_button__strategic_planning,
		0,
		true,
		true,
		false,
		new ArrayList<FmmNode>(Arrays.asList(
				FmmNodeDictionary.FISCAL_YEAR,
				FmmNodeDictionary.STRATEGIC_MILESTONE,
				FmmNodeDictionary.PROJECT_ASSET )) ),
	WORK_BREAKDOWN (
		R.string.perspective__work_breakdown,
		R.drawable.perspective__work_breakdown,
		R.id.perspective_button__work_breakdown,
		1,
		true,
		true,
		false,
		new ArrayList<FmmNode>(Arrays.asList(
				FmmNodeDictionary.PORTFOLIO,
				FmmNodeDictionary.PROJECT,
				FmmNodeDictionary.PROJECT_ASSET,
				FmmNodeDictionary.WORK_PACKAGE )) ),
	WORK_PLANNING (
		R.string.perspective__work_planning,
		R.drawable.perspective__work_planning,
		R.id.perspective_button__work_planning,
		2,
		true,
		true,
		false,
		new ArrayList<FmmNode>(Arrays.asList(
				FmmNodeDictionary.FISCAL_YEAR,
				FmmNodeDictionary.FLYWHEEL_MILESTONE,
				FmmNodeDictionary.WORK_PLAN,
				FmmNodeDictionary.WORK_PACKAGE )) ),
	ANALYSIS (
		R.string.perspective__analysis,
		R.drawable.perspective__analysis,
		R.id.perspective_button__analysis,
		3,
		true,
		true,
		false,
		new ArrayList<FmmNode>(Arrays.asList(
				FmmNodeDictionary.BOOKSHELF,
				FmmNodeDictionary.NOTEBOOK,
				FmmNodeDictionary.DISCUSSION_TOPIC,
				FmmNodeDictionary.PROJECT_ASSET,
				FmmNodeDictionary.WORK_PACKAGE,
				FmmNodeDictionary.WORK_TASK,
				FmmNodeDictionary.FACILITATION_ISSUE )) ),
	COMMITMENTS (
		R.string.perspective__commitments,
		R.drawable.perspective__commitments,
		R.id.perspective_button__commitments,
		4,
		true,
		true,
		false,
		new ArrayList<FmmNode>(Arrays.asList(
				FmmNodeDictionary.FISCAL_YEAR,
				FmmNodeDictionary.STRATEGIC_MILESTONE,
				FmmNodeDictionary.PROJECT_ASSET,
				FmmNodeDictionary.FLYWHEEL_MILESTONE,
				FmmNodeDictionary.WORK_PACKAGE,
				FmmNodeDictionary.SERVICE_REQUEST )) ),
	SERVICE_DELIVERY (
		R.string.perspective__service_delivery,
		R.drawable.perspective__service_delivery,
		R.id.perspective_button__service_delivery,
		5,
		true,
		true,
		false,
		new ArrayList<FmmNode>(Arrays.asList(
				FmmNodeDictionary.FISCAL_YEAR,
				FmmNodeDictionary.FLYWHEEL_MILESTONE,
				FmmNodeDictionary.SERVICE_REQUEST_TRIAGE_LOG,
				FmmNodeDictionary.SERVICE_OFFERING,
				FmmNodeDictionary.SERVICE_REQUEST )) ),
	GOVERNANCE (
		R.string.perspective__governance,
		R.drawable.perspective__governance,
		R.id.perspective_button__governance,
		5,
		true,
		true,
		false,
		new ArrayList<FmmNode>(Arrays.asList(
				FmmNodeDictionary.GOVERNANCE_ROLE,
				FmmNodeDictionary.COMMUNITY_MEMBER,
				FmmNodeDictionary.GOVERNANCE_TARGET )) ),
	COMMUNITY (
		R.string.perspective__community,
		R.drawable.perspective__community,
		R.id.perspective_button__community,
		6,
		true,
		true,
		false,
		new ArrayList<FmmNode>(Arrays.asList(
				FmmNodeDictionary.ORGANIZATION,
				FmmNodeDictionary.STRATEGIC_TEAM,
				FmmNodeDictionary.FLYWHEEL_TEAM,
				FmmNodeDictionary.FUNCTIONAL_TEAM,
				FmmNodeDictionary.COMMUNITY_MEMBER )) ),
	FACILITATION_ISSUES (
		R.string.perspective__facilitation_issues,
		R.drawable.perspective__facilitation_issues,
		R.id.perspective_button__facilitation_issues,
		7,
		true,
		true,
		false,
		new ArrayList<FmmNode>(Arrays.asList(
				FmmNodeDictionary.GOVERNANCE_TARGET,
				FmmNodeDictionary.FACILITATION_ISSUE )) );
	
	// These need to be added to the array in menu order.
	public static final FmmPerspective[] CONTEXT_MENU_ARRAY = {
		STRATEGIC_PLANNING,
		WORK_BREAKDOWN,
		WORK_PLANNING,
		ANALYSIS,
	};
	
	// These need to be added to the array in menu order.
	public static final FmmPerspective[] MENU_ARRAY = {
		STRATEGIC_PLANNING,
		COMMITMENTS,
		WORK_BREAKDOWN,
		WORK_PLANNING,
		SERVICE_DELIVERY,
		GOVERNANCE,
		ANALYSIS,
		COMMUNITY,
		FACILITATION_ISSUES
	};
	
	public static String getName(int aMenuSequence) {
		for (FmmPerspective theFmmPerspective : MENU_ARRAY) {
			if (theFmmPerspective.getMenuSequence() == aMenuSequence) {
				return theFmmPerspective.getName();
			}
		}
		return null;
	}
	
	private static final HashMap<String, FmmPerspective> nameMap = new HashMap<String, FmmPerspective>();
	static {
		FmmPerspective.nameMap.put(COMMITMENTS.getName(), COMMITMENTS);
		FmmPerspective.nameMap.put(COMMUNITY.getName(), COMMUNITY);
		FmmPerspective.nameMap.put(ANALYSIS.getName(), ANALYSIS);
		FmmPerspective.nameMap.put(FACILITATION_ISSUES.getName(), FACILITATION_ISSUES);
		FmmPerspective.nameMap.put(GOVERNANCE.getName(), GOVERNANCE);
		FmmPerspective.nameMap.put(SERVICE_DELIVERY.getName(), SERVICE_DELIVERY);
		FmmPerspective.nameMap.put(STRATEGIC_PLANNING.getName(), STRATEGIC_PLANNING);
		FmmPerspective.nameMap.put(WORK_BREAKDOWN.getName(), WORK_BREAKDOWN);
		FmmPerspective.nameMap.put(WORK_PLANNING.getName(), WORK_PLANNING);
	}

	public static FmmPerspective getObjectForName(String aName) {
		return FmmPerspective.nameMap.get(aName);
	}

	private int nameStringResourceId;
	private String name;
	private int iconDrawableResourceId;
	private Drawable iconDrawable;
	private int buttonResourceId;
	private Button button;
	private int menuSequence;
	private boolean enabled;
	private boolean showPerspective;
	private boolean showNoOpPrototype = false;
	private int prototypeResourceId = 0;
	private ArrayList<FmmNode> treeNodeTypeList = new ArrayList<FmmNode>();
	
	private FmmPerspective(
			int aNameStringResourceId,
			int anIconDrawableResourceId,
			int aButtonResourceId,
			int aMenuSequence,
			boolean bEnabled,
			boolean aShowPerspective,
			boolean bShowNoOpPrototype,
			ArrayList<FmmNode> aTreeNodeTypeList ) {
		this.nameStringResourceId = aNameStringResourceId;
		this.name = FmmHelper.getContext().getResources().getString(this.nameStringResourceId);
		this.iconDrawableResourceId = anIconDrawableResourceId;
		this.iconDrawable = FmmHelper.getContext().getResources().getDrawable(this.iconDrawableResourceId);
		this.buttonResourceId = aButtonResourceId;
		this.menuSequence = aMenuSequence;
		this.enabled = bEnabled;
		this.showPerspective = bEnabled == true ? aShowPerspective : false;
		this.showNoOpPrototype = bShowNoOpPrototype;
		this.treeNodeTypeList = aTreeNodeTypeList;
	}
	
	public String getName() {
		return this.name;
	}

	public int getIconDrawableResourceId() {
		return this.iconDrawableResourceId;
	}
	
	public Drawable getIconDrawable() {
		return this.iconDrawable;
	}

	public int getButtonDrawableResourceId() {
		return this.buttonResourceId;
	}
	
	public Button getButton(View aView) {
		if(this.button == null) {
			this.button = (Button) aView.findViewById(this.buttonResourceId);
		}
		return this.button;
	}
	
	public int getMenuSequence() {
		return this.menuSequence;
	}
	
	public boolean isEnabled() {
		return this.enabled;
	}
	
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	
	public boolean isShowPerspective() {
		return this.showPerspective;
	}
	
	public void setShowPerspective(boolean bShowPerspective) {
		this.showPerspective = bShowPerspective;
	}
	
	public boolean showNoOpPerspectivePrototype() {
		return this.showNoOpPrototype;
	}
	
	public Drawable getPrototypeDrawable() {
		return FmmHelper.getContext().getResources().getDrawable(this.prototypeResourceId);
	}
	
	public ArrayList<FmmNode> getTreeNodeTypeList() {
		return this.treeNodeTypeList;
	}
	
	@Override
	public String toString() {
		return this.name;
	}
	
	public static FmmPerspective getPerspectiveForName(String aPerspectiveName) {
		for (FmmPerspective thePerspective : FmmPerspective.values()) {
			if (thePerspective.toString().equals(aPerspectiveName)) {
				return thePerspective;
			}
		}
		return null;
	}

}
